package com.bi.dataDmTrans.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bi.dataDmTrans.entity.DataItem1;
import com.bi.dataDmTrans.mapper.DataItem1Mapper;
import com.bi.dataDmTrans.service.DataItem1Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class DataItem1ServiceImpl extends ServiceImpl<DataItem1Mapper, DataItem1> implements DataItem1Service {

    @Override
    public void saveDataToDatabase(List<DataItem1> data, int pageNum) {
        log.info("开始保存数据,数据量:{}", data.size());
        if (!data.isEmpty()) {
            try {
                log.info("开始插入数据");
                // 批量插入数据
                boolean result = this.saveBatch(data);
                if (result) {
                    log.info("数据插入完成,{}", pageNum);
                } else {
                    log.error("数据插入失败，{}", pageNum);
                }
            } catch (Exception e) {
                log.error("数据插入过程中发生错误,{},{}", e, pageNum);
            }
        } else {
            log.warn("数据为空，未执行插入操作,{}", pageNum);
        }
    }
}
